<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>返回集合中的文档数量</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.construct.html">MongoCollection::__construct</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongocollection.createdbref.html">MongoCollection::createDBRef</a></div>
 <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mongocollection.count" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">MongoCollection::count</h1>
  <p class="verinfo">(PECL mongo &gt;=0.9.0)</p><p class="refpurpose"><span class="refname">MongoCollection::count</span> &mdash; <span class="dc-title">返回集合中的文档数量</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mongocollection.count-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type">int</span> <span class="methodname"><strong>MongoCollection::count</strong></span>
    ([ <span class="methodparam"><span class="type">array</span> <code class="parameter">$query</code><span class="initializer"> = array()</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$limit</code><span class="initializer"> = 0</span></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$skip</code><span class="initializer"> = 0</span></span>
  ]]] )</div>

 </div>

 
 <div class="refsect1 parameters" id="refsect1-mongocollection.count-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>

      <em><code class="parameter">query</code></em>
     </dt>

     <dd>

      <p class="para">
       关联数组或者对象，含有需要匹配的字段。
      </p>
     </dd>

       
    
     <dt>

      <em><code class="parameter">limit</code></em>
     </dt>

     <dd>

      <p class="para">
       指定返回数量的上限。
      </p>
     </dd>

       
    
     <dt>

      <em><code class="parameter">skip</code></em>
     </dt>

     <dd>

      <p class="para">
       指定在开始统计前，需要跳过的结果数目。
      </p>
     </dd>

       
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mongocollection.count-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回查询匹配到的文档数目。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-mongocollection.count-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>1.0.7</td>
       <td>
        添加了 <em><code class="parameter">limit</code></em> 和 <em><code class="parameter">skip</code></em>
        参数。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mongocollection.count-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="example-1406">
   <p><strong>Example #1 <span class="function"><strong>MongoCollection::count()</strong></span> 例子</strong></p>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'x'</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">1</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'x'</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">2</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">insert</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'x'</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">3</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">count</span><span style="color: #007700">());<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$collection</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">count</span><span style="color: #007700">(array(</span><span style="color: #DD0000">'x'</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">1</span><span style="color: #007700">)));<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

   <div class="example-contents"><p>以上例程的输出类似于：</p></div>
   <div class="example-contents screen">
<div class="cdata"><pre>
int(3)
int(1)
</pre></div>
   </div>
  </div>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mongocollection.construct.html">MongoCollection::__construct</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mongocollection.createdbref.html">MongoCollection::createDBRef</a></div>
 <div class="up"><a href="class.mongocollection.html">MongoCollection</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
